<template>
  <view class="u-m-b-14 bg-fff">
    <view :style="{'padding-bottom': showEva?'65px':'0'}">
      <view class="title u-p-b-30 u-p-t-30 u-flex u-row-between u-p-r-28">
        <view class="title-txt u-p-l-20 u-font-36">全部评价</view>
      </view>
      <evaList :list="list" border  @like-change="res => list = res" :type="type"/>
      <u-loadmore :status="status" />
    </view>
    <view class="bottom bg-fff" v-if="showEva">
      <u-button type="primary" :custom-style="customStyle121"
                @click="jump"
                shape="circle">我也来评价</u-button>
    </view>
  </view>
</template>

<script>
import {request} from "../../util/api";
import evaList from "../../components/evaList";
import {THEME} from "../mixins/config";

export default {
  name: "list",
  components: {
    evaList
  },
  onLoad (option) {
    this.id = option.id
    this.queryForm.videoId = option.id
    this.type = option.type
    this.allFree = option.allFree
  },

  data () {
    return {
      type: '',
      list: [],
      status: 'loadmore',
      queryForm: {
        pageNum: 1,
        pageSize: 20
      },
      id: '',
      customStyle121: {
        background: THEME.btn_active_bg_color,
        padding: '0 30rpx',
        width: '90%'
      },
      showEva: false,
      allFree: false
    }
  },

  onShow() {
    this.queryForm.pageNum = 1
    this.list = []
    this.getList()
    var user = uni.getStorageSync('zbz_user')
    if (user && user.token) {
      if (this.allFree === 'true') {
        this.showEva = true
      } else {
        this.getBuyDetail()
      }
    }
  },

  methods: {
    getList() {
      this.status = 'loading'
      if (this.type == 'goods') {
        request({
          url: '/system/CompassGoodsEva/list',
          data: Object.assign({goodsId: this.id}, this.queryForm)
        }).then(res => {
          this.list = this.list.concat(res.rows)
          if (this.list.length < res.total) {
            this.status = 'loadmore'
          } else {
            this.status = 'more'
          }
        })
      } else {
        request({
          url: '/system/CompassVideoEva/list',
          data: Object.assign({videoId: this.id}, this.queryForm)
        }).then(res => {
          this.list = this.list.concat(res.rows)
          if (this.list.length < res.total) {
            this.status = 'loadmore'
          } else {
            this.status = 'more'
          }
        })
      }
    },

    getBuyDetail () {
      request({
        url: '/app/userCenter/getLoginUserInfo'
      }).then(res => {
        let endEvaluateTime = new Date(res.data.endEvaluateTime).getTime()
        let _now = new Date().getTime()
        if (_now > endEvaluateTime) {
          this.showEva = false
        } else {
          this.showEva = true
        }
      })
    },

    jump() {
      this.$u.route({
        url: '/pages/comment/add',
        params: {
          id: this.id,
          type: this.type
        }
      })
    }
  },

  onReachBottom() {
    if (this.status == 'loadmore') {
      this.queryForm.pageNum++
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">

.title {
  .title-txt {
    border-left: 8upx solid $text_active_color;
  }
}

.bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 20upx 0;
  z-index: 10;
}
</style>
